package com.chendongyang.www.service;//进行用户对充电站的选择（去充电或者结束充电）
import com.chendongyang.www.dao.charge;
import com.chendongyang.www.po.chargingStation;
import com.chendongyang.www.util.userId;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;

public class charges {
    public  void charging() throws SQLException {
        charge udi=new charge();
            ArrayList<chargingStation> list = udi.select1();
            ArrayList<chargingStation> List=udi.select(userId.Id);
        System.out.println("===============");
        boolean check=udi.select1(userId.Id);
        if(check==false){
            System.out.println("您是校外人士，无法进行充电");
            return;
        }
        boolean check1=udi.select2(userId.Id);
        if(check1==false){
            System.out.println("您的电动车还没有上牌，无法进行充电");
            return;
        }
        System.out.println(userId.Id);
        if(List.size()==1){
            System.out.println("====================");
            System.out.println("您现在正在充电中");
            System.out.println("所用充电站为：");
            System.out.println(List.get(0));
            System.out.println("====================");
            System.out.println("请选择是否继续充电");
            System.out.println("1    继续充电");
            System.out.println("2    结束充电");
            Scanner input = new Scanner(System.in);
            int op=input.nextInt();
            if(op==2){
               int number= udi.over(userId.Id);
               if(number==1) System.out.println("结束成功");
                System.out.println("======================");
            }
            else System.out.println("已继续充电中");
        }
        else {
            System.out.println("现有以下可用充电站");
            int m = list.size();
            for (int i = 0; i < m; i++) {
                System.out.print(i + 1 + ":");
                System.out.println(list.get(i));
            }
            System.out.println("================");
            System.out.println("请选择充电站和充电位进行充电");
            Scanner input = new Scanner(System.in);
            int op = input.nextInt();
            String station = list.get(op - 1).getChargeS();
            String bit = list.get(op - 1).getChargeB();
            int line = udi.update(station, bit,userId.Id);
            if (line == 1) {
                System.out.println("开始充电");
                System.out.println("===================");
            } else {
                System.out.println("充电失败");
                System.out.println("====================");
            }
        }
    }
}
